<template>
  <el-upload :data="dataObj" :multiple="true" action="https://up-z1.qiniup.com" drag>
    <i class="el-icon-upload" />
    <div class="el-upload__text">
      将文件拖到此处，或<em>点击上传</em>
    </div>
  </el-upload>
</template>

<script>
import { getToken } from '@/api/qiniu'
// 获取七牛token 后端通过Access Key,Secret Key,bucket等生成token
// 七牛官方sdk https://developer.qiniu.com/sdk#official-sdk

export default {
  data () {
    return {
      dataObj: { token: '', key: '' },
      image_uri: [],
      fileList: []
    }
  },
  methods: {
    beforeUpload () {
      var self = this
      getToken().then(res => {
        this.$message({
          message: res.data,
          type: 'success',
          duration: 5 * 1000
        })
        self.dataObj.token = res.data.token
        self.dataObj.key = res.data.key
        self.token = res.data
      })
    }
  },
  mounted () {
    this.beforeUpload()
  }
}
</script>
